package com.southwind.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @author Frankioxo
 * @date 2023-02-25 16:43
 * @description
 */
@RestController
// @RequestMapping("/test")
public class TestController {

    @RequestMapping(value = "test1")
    public String testSession(HttpServletRequest request) {
        HttpSession session = request.getSession();
        // log.info("sessionId:[{}]", session.getId());
        session.setAttribute("name", "Lucy");
        session.setAttribute("age", "20");
        // String id = session.getId();

        // return session.getAttribute("name").toString();
        return session.getId();
    }

    @RequestMapping(value = "test2")
    public String testSession2(HttpServletRequest request) {
        HttpSession session = request.getSession();
        // log.info("sessionId:[{}]", session.getId());
        // session.setAttribute("name", "Lucy");
        // session.setAttribute("age", "20");
        // String id = session.getId();

        session.removeAttribute("name");
        session.removeAttribute("age");

        // return session.getAttribute("name").toString();
        return session.getId();
    }



}
